Crate cdt[−][src]
Expand description
cdt
is a library for calculating
Delaunay and
constrained Delaunay
triangulations.
It is optimized for correctness and speed, using exact predicates to perform point-in-circle and orientation tests.
Examples
Delaunay triangulation
This triangulates a set of four points in a square
let pts = vec![(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]; let triangles = cdt::triangulate_points(&pts).unwrap(); assert!(triangles.len() == 2); for t in triangles { println!("{:?} {:?} {:?}", pts[t.0], pts[t.1], pts[t.2]) }
Constrained Delaunay triangulation
This triangulates an inner and outer square
let pts = vec![(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.2, 0.2), (0.8, 0.2), (0.8, 0.8), (0.2, 0.8)]; let triangles = cdt::triangulate_contours(&pts, &[vec![0, 1, 2, 3, 0], vec![4, 5, 6, 7, 4]]) .unwrap(); for t in triangles { println!("{:?} {:?} {:?}", pts[t.0], pts[t.1], pts[t.2]) }
Crate features
By default, the library uses u32
indexes for internal data structures,
to improve performance. If you are planning to triangulate more than 500M
points in a single pass, you should enable the long-indexes
feature.
Structs
This struct
contains all of the data needed to generate a (constrained)
Delaunay triangulation of a set of input points and edges. It is a
low-level API; consider using the module-level functions if you don’t
need total control.
Enums
Single error type for this library
Functions
Given a set of points and edges which are known to panic, figures out the max number of save steps, then saves an SVG right before the panic occurs
Triangulates a set of contours, given as indexed paths into the point list.
Each contour must be closed (i.e. the last point in the contour must equal
the first point), otherwise Error::OpenContour
will be returned.
Triangulates a set of points, returning triangles as triples of indexes into the original points list. The resulting triangulation has a convex hull.
Triangulates a set of points with certain fixed edges. The edges are assumed to form closed boundaries; only triangles within those boundaries will be returned.